

// 混入（mixin）提供了一种非常灵活的方法，来分发vue 组件中的可复用功能
// 一个混入对象可以包含任意组件选项
// Vue.mixin  全局混入
// Vue.mixins  局部混入

import Vue from "vue"
import { mapState, mapMutations } from "vuex"
import { FootList } from "."
import { getCookie, setCookie, delCookie } from "./cookie"
import { reg } from "@/utils/validate"
import { ShowError, ShowSuccess } from "@/api/request"

Vue.mixin({
    data() {
        return {
            wh2110: "wh2110",
            FootList: FootList,
            reg,
            dpr: window.devicePixelRatio
        }
    },
    computed: {
        ...mapState([
            "username",
            "cartNum",
            "userInfo",
            "city",
            "cityList",
            'cinemaList'
        ])
    },
    created() {

    },
    methods: {
        // 检测是否有城市信息
        checkHasCityInfo(callback) {
            if (this.city) {
                // 请求数据的回调 
                callback()
            } else {
                this.$dialog.alert({
                    title: '选择城市',
                    message: '你尚未定位选择城市,请前往选择',
                }).then(() => {
                    // on close
                    this.$router.push({ name: 'city' })
                });
            }

        },
        ShowError,
        ShowSuccess,
        getCookie,
        setCookie,
        delCookie,
        ...mapMutations([
            "changeUserInfo",
            "changeCity",
            "changeCityList",
            "changeCinemaList"
        ]),
        gotopage(name) {
            this.$router.push({ name })
        }
    },
    mounted() {
        // console.log("全局混入的");
    },
    watch: {

    }
})